package com.hopu.haogoumall.db.mapper;

import com.hopu.haogoumall.db.module.HaogoumallSearchHistory;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface HaogoumallSearchHistoryMapper {
    @Delete({
        "delete from haogoumall_search_history",
        "where search_history_id = #{searchHistoryId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer searchHistoryId);

    @Insert({
        "insert into haogoumall_search_history (search_history_id, user_id, ",
        "search_keyword, search_from, ",
        "search_history_add_time, search_history_update_time, ",
        "search_history_deleted)",
        "values (#{searchHistoryId,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, ",
        "#{searchKeyword,jdbcType=VARCHAR}, #{searchFrom,jdbcType=VARCHAR}, ",
        "#{searchHistoryAddTime,jdbcType=TIMESTAMP}, #{searchHistoryUpdateTime,jdbcType=TIMESTAMP}, ",
        "#{searchHistoryDeleted,jdbcType=BIT})"
    })
    int insert(HaogoumallSearchHistory record);

    @InsertProvider(type=HaogoumallSearchHistorySqlProvider.class, method="insertSelective")
    int insertSelective(HaogoumallSearchHistory record);

    @Select({
        "select",
        "search_history_id, user_id, search_keyword, search_from, search_history_add_time, ",
        "search_history_update_time, search_history_deleted",
        "from haogoumall_search_history",
        "where search_history_id = #{searchHistoryId,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="search_history_id", property="searchHistoryId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER),
        @Result(column="search_keyword", property="searchKeyword", jdbcType=JdbcType.VARCHAR),
        @Result(column="search_from", property="searchFrom", jdbcType=JdbcType.VARCHAR),
        @Result(column="search_history_add_time", property="searchHistoryAddTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="search_history_update_time", property="searchHistoryUpdateTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="search_history_deleted", property="searchHistoryDeleted", jdbcType=JdbcType.BIT)
    })
    HaogoumallSearchHistory selectByPrimaryKey(Integer searchHistoryId);

    @UpdateProvider(type=HaogoumallSearchHistorySqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(HaogoumallSearchHistory record);

    @Update({
        "update haogoumall_search_history",
        "set user_id = #{userId,jdbcType=INTEGER},",
          "search_keyword = #{searchKeyword,jdbcType=VARCHAR},",
          "search_from = #{searchFrom,jdbcType=VARCHAR},",
          "search_history_add_time = #{searchHistoryAddTime,jdbcType=TIMESTAMP},",
          "search_history_update_time = #{searchHistoryUpdateTime,jdbcType=TIMESTAMP},",
          "search_history_deleted = #{searchHistoryDeleted,jdbcType=BIT}",
        "where search_history_id = #{searchHistoryId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(HaogoumallSearchHistory record);
}